package com.myk.game.heroscuffle.heroes;

import com.myk.game.heroscuffle.game.Element;
import com.myk.game.heroscuffle.game.Hero;
import com.myk.game.heroscuffle.game.Sign;
import com.myk.game.heroscuffle.game.Skill;
import com.myk.game.heroscuffle.skills.Skill_ChuiJi;
import com.myk.game.heroscuffle.skills.Skill_LiuXing;
import com.myk.game.heroscuffle.utils.RdmPropUtil;

public class Hero_LinLin extends Hero {

    private boolean hasChance = true; //是否还有锁血的机会

    /**
     * 攻防都高，生命值低
     */
    public Hero_LinLin() {
        super("凛凛",
                "血量越低战斗力越高，受到致死伤害时有一次机会让生命值锁定为1。",
                Element.ICE, 1300, 120, 52,
                new Skill_ChuiJi());
    }

    @Override
    public void onAutoSelectAction() {
        Skill chuiji = getUsableSkill(Skill_ChuiJi.class);
        if (chuiji != null) {
            if (RdmPropUtil.bingo(1/2d)) {
                useSkill(chuiji);
            }
            else {
                super.onAutoSelectAction();
            }
        }
        else {
            super.onAutoSelectAction();
        }
    }

    @Override
    public void onAfterSufferDamage(Hero attacker, Skill skill, Sign sign, int damage) {
        if (hp <= 0) { //遇到致死伤害时
            if (hasChance) { //若还有一次锁血的机会，进行锁血
                hasChance = false;
                game.ui.printMsg(getObviousName() + "以坚强的意志争取一线生机,");
                hp = 1;
            }
        }
        else { //血量降低时增加攻击力和防御力
            int atkAdd = (HP - hp) / 100 * 5; //每减少100点hp，atk增加5点
            int afterAtk = ATK + atkAdd; //增幅后atk的值
            if (atk < afterAtk) {
                atk = afterAtk;
                game.ui.printMsg(getObviousName() + "燃起热血,atk增加至" + afterAtk + "点，");
                game.ui.sleepShortly();
            }
        }
    }
}
